(function() {
  'use strict';

  define(['app','services/StoreManager', 'bootstrap'], function(AMail) {
    AMail.controller('NewMessage', ['$scope', 'StoreManager', '$location', function($scope, StoreManager, $location) {
      $scope.submit = function() {
        var messages = StoreManager.getItem("AMail");

        messages = messages ? messages : [];
        messages.push({
          'id': messages.length,
          "sender": "wusende@gmail.com",
          "subject": $scope.subject,
          "date": new Date() + "",
          "to": $scope.to,
          "cc": $scope.cc,
          "message": $scope.message
        });

        StoreManager.setItem("AMail", messages);

        $("#save-result").modal();
        return true;
      };

      $scope.backtolist = function() {
        $location.path('/' + new Date().getTime());
      };

      $scope.newMessage = function() {
        $location.path("/new/" + new Date().getTime());
      };
    }]);
  });
}).call(this);